<?php

    class ThemesResource extends Resource
    {
        const ID = "themes";

        public function GetId()
        {
            return self::ID;
        }

        public function GetFreshData()
        {
            return $this->GetThemes();
        }

        /**
         * Returns array of ThemeInfo objects, loaded from the theme data file.
         *
         * @return array
         */
        private function GetThemes()
        {
            $xml = Core::ThemeSubstitutions()->Process( @file_get_contents( THEMES_FILE ) );
            $doc = Util::CreateXmlDocument( $xml, true );
            if ( $doc )
            {
                $themes = array();
                $xpath = new XPathHelper( $doc );
                $nodes = $xpath->GetNodes( "/themes/theme" );
                foreach ( $nodes as $node )
                {
                    if ( $node->hasAttribute( "id" ) )
                    {
                        $theme = new ThemeInfo();
                        $theme->id               = $node->getAttribute( "id" );
                        $theme->showBreadcrumbs  = $node->getAttribute( "showBreadcrumbs" );
                        $theme->top_menu         = $xpath->GetText("top_menu",     $node);
                        $theme->bottom_menu      = $xpath->GetText("bottom_menu",  $node);
                        $theme->javascripts      = Util::ToArrayValue($xpath->GetText("javascripts",  $node));
                        $theme->stylesheets      = Util::ToArrayValue($xpath->GetText("stylesheets",  $node));

                        $theme->left             = $xpath->GetText("left",  $node);
                        $theme->right            = $xpath->GetText("right",  $node);
                        $theme->top              = $xpath->GetText("top",  $node);
                        $theme->bottom           = $xpath->GetText("bottom",  $node);

                        $themes[$theme->id] = $theme;
                    }
                }

                return $themes;
            }
            return array();
        }
    }

?>